﻿Imports System.Data.SqlClient

Public Class NhuCauBUS
    
    Public Shared Function GetByMaKhach(ByVal makhach As String) As DataTable
        Dim dt As New DataTable()

        Dim para As SqlParameter = New SqlParameter("maKH", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = makhach

        dt = NhuCauDAO.GetByMaKhach(para)

        Return dt
    End Function

    Public Shared Sub Insert(ByVal nhucau As NhuCauDTO)
        Dim parametersNhuCau(3) As SqlParameter

        Dim para As SqlParameter
        para = New SqlParameter("MaLoaiNha", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iMaLoaiNha
        parametersNhuCau(0) = para

        para = New SqlParameter("MaQuan", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iMaQuan
        parametersNhuCau(1) = para

        para = New SqlParameter("KhoangGia", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iKhoangGia
        parametersNhuCau(2) = para

        para = New SqlParameter("MaKhachThue", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.strMaKhachThue
        parametersNhuCau(3) = para

        NhuCauDAO.Insert(parametersNhuCau)

    End Sub


    Public Shared Sub Update(ByVal nhucau As NhuCauDTO)
        Dim parametersNhuCau(4) As SqlParameter

        Dim para As SqlParameter
        para = New SqlParameter("MaNhuCau", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iMaNhuCau
        parametersNhuCau(0) = para

        para = New SqlParameter("MaLoaiNha", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iMaLoaiNha
        parametersNhuCau(1) = para

        para = New SqlParameter("MaQuan", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iMaQuan
        parametersNhuCau(2) = para

        para = New SqlParameter("KhoangGia", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.iKhoangGia
        parametersNhuCau(3) = para

        para = New SqlParameter("MaKhachThue", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = nhucau.strMaKhachThue
        parametersNhuCau(4) = para

        NhuCauDAO.Update(parametersNhuCau)
    End Sub

    Public Shared Function KiemTraDayDu(ByVal khoanggia As String)
        Dim kq As Boolean
        If Not khoanggia = "" Then
            If IsNumeric(khoanggia) Then
                kq = True
            Else
                kq = False
            End If
        Else
            kq = False
        End If

        Return kq
    End Function
End Class
